import store from '@/store'
import { EventBus } from '@/store/index'
import { H5_TYPE } from '@/common/const-dif'
import { nextTick } from 'vue'


export default class BasePixiCon {
	constructor() {
    this.item = null;
    this.commonAttr = null;
    this.conAttr = null;
    this.container_ = null;
    this.store = store;
  }

  initPixi({item}) {
    this.item = item;
    this.commonAttr = item.commonAttr;
    this.conAttr = item.conAttr;
  }

  get container(){
    return this.container_;
  }
  set container(con){
    this.container_ = con;
  }
  get componentMap() {
    return this.store.state.componentMap;
  }
  get controls() {
    return this.store.state.controls ? this.store.state.controls : this.store.state.wbComponents.controls;
  }
  get allPages() {
    return this.store.state.allPages ? this.store.state.allPages : this.store.state.components.controls;
  }
  get wbUserData() {
    return this.store.state.userInfo.wbUserData;
  }
  get userInfo() {
    return this.store.state.userInfo;
  }
  get interactionData() {
    return this.store.state.interactionData;
  }
  get frontData() {
    return this.store.state.frontData;
  }
  get formValues() {
    return this.store.state.formValues;
  }
  get globalIsPost() {
    return this.store.state.globalIsPost;
  }
  get pages() {
    return this.store.state.pages;
  }
  get pops() {
    return this.store.state.pops_;
  }
  get statePopId() {
    return this.store.state.popId;
  }
  get pageIndex() {
    return this.store.state.pageIndex;
  }
  get siteAttrs() {
    return this.store.state.attrs;
  }

  get timeObj() {
    return this.store.state.timeObj;
  }

  get appid() {
    return this.store.state.attrs.wb_appkey;
  }
  get uid() {
    return this.store.state.userInfo.uid;
  }
  get siteInfo() {
    return this.store.state.siteInfo;
  }
   get bindData() {
     return this.store.state.bindData;
   }

  initContainer(PIXI) {
    const container = this.container_ = new PIXI.Container()
    this.app.stage.addChild(container)
  }

  showPage(pageId) {
    if(!this.pages[pageId-1]){
      return
    }
    if (this.statePopId > 0) {
      EventBus.$emit('closePop')
    }

    EventBus.$emit("isStartHtml2canvas", { isStart: true, compId: this.item.id});
    let pageIndex = pageId - 1
    this.store.commit('updatePageIndex', { pageIndex })

    EventBus.$emit('pauseVideo', { pageId })
    EventBus.$emit('playOrPauseAudio', { isPlay: false })
    if (this.siteAttrs.h5Type == H5_TYPE.mobile && !this.siteAttrs.isNoSwiping && this.siteAttrs.pageType == PAGE_TYPE.single) {
      EventBus.$emit("swiper", { pageId })
    } else {
      EventBus.$emit('showPage', { pageId })
    }
    nextTick(() => {
      EventBus.$emit("isStartHtml2canvas", { isStart: false, compId: this.item.id});
    })
  }
  
  destroy() {
    this.item = null;
    this.commonAttr = null;
    this.conAttr = null;
    this.container_ = null;
  }
}